﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;

namespace Dare.Utilities.Data
{
    public sealed class DbUtil
    {
        #region Constructors
        private DbUtil() {/*All static methods*/}
        #endregion

        /// <summary>
        /// 获得数据提供工厂
        /// </summary>
        /// <param name="assemblyPath">数据提供程序DLL文件(绝对/相对路径都可)(</param>
        /// <param name="className">数据提供工厂类名</param>
        /// <returns></returns>
        public static DbProviderFactory GetDbProviderFactoryFrom(string assemblyFile, string factoryClassName)
        {
            return ReflectionUtil.GetPublicStaticFieldFrom<DbProviderFactory>(assemblyFile, factoryClassName, "Instance");
        }

        /// <summary>
        /// 获得数据提供工厂
        /// </summary>
        /// <param name="providerInvariantName">提供程序的固定名称</param>
        /// <returns></returns>
        public static DbProviderFactory GetDbProviderFactory(string providerInvariantName)
        {
            return DbProviderFactories.GetFactory(providerInvariantName);
        }
    }
}
